/*
*
* 正方形的缓冲区绘制
* r: 半边长
*
 */
function Square_bufferInit(gl, r=0.8) {

    //创建位置
    const positions = [
        r, 0, r,
        r, 0, -r,
        -r, 0, -r,
        -r, 0, r,
    ];

    const positionBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, positionBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);

    //创建颜色
    const color = [0.4, 0.6, 0.7, 1.0];

    var faceColors = [];

    for (var i = 0; i < 4; i++) {
        faceColors = faceColors.concat(color);
    }

    const colorBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, colorBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(faceColors), gl.STATIC_DRAW);

    //创建面单元
    const surfaces = [
        0, 1, 3, 2,
    ];

    const surfaceBuf = gl.createBuffer();
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, surfaceBuf);
    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(surfaces), gl.STATIC_DRAW);

    return {
        position: positionBuf,
        color: colorBuf,
        surface: surfaceBuf,
        drawmode: gl.TRIANGLE_STRIP,
        drawcount: 4,
        transparent: false,
    };
}